#! /usr/bin/env python
# coding=utf-8

import argparse
import sys
from argparse import RawTextHelpFormatter


parser = argparse.ArgumentParser(
    description='''
    将 下载的gff文件进行过滤 获得运行gemoma的gff参考文件

    用法:
    gemoma_make_lib.py -i api.gff -o modified.gff
    ''',formatter_class=RawTextHelpFormatter)



parser.add_argument('-i',
                help='必须给定，输入的gff文件 ')



parser.add_argument('-o',
                help='输出的gff文件')


args = parser.parse_args()

if not args.i or not args.o:
    parser.print_help()
    sys.exit()



infile = args.i
outfile  = args.o



outfile = open(outfile,'w')

gffhead = outfile.write('##gff-version 3\n')


n = 1

with open(infile) as fila:
	for i in fila:
		k = i.split('#')[0].strip().split('\t')
		if len(k)>8:
			n += 1
			t = [j for j in k[8].split(';') if j.split('=')[0] in ['ID','Parent','Name']]
			k[8] = ';'.join(t).replace('(','').replace(')','').replace('+','').replace('/','')

			z = '\t'.join(k)
			outfile.write(z+'\n')
outfile.close()


			